package com.vmj.heap;

/**
 * Created by yangshoujun on 2017/8/26 下午2:15.
 */
public class SymRef {

    private RuntimeConstantPool runtimeConstantPool;
    private String className;
    private VMClass clazz;

    public VMClass resolvedClass() {
        if(clazz == null) {
            resolvedClassRef();
        }
        return clazz;
    }

    private void resolvedClassRef() {
        VMClass clazz = runtimeConstantPool.getClazz();
        VMClass oClazz = clazz.getClassLoader().loadClass(this.className);
        if(!oClazz.isAccessibleTo(clazz)) {
            throw new RuntimeException("java.lang.IllegalAccessException");
        }
        this.clazz = oClazz;
    }

    public RuntimeConstantPool getRuntimeConstantPool() {
        return runtimeConstantPool;
    }

    public String getClassName() {
        return className;
    }

    public VMClass getClazz() {
        return clazz;
    }

    public void setRuntimeConstantPool(RuntimeConstantPool runtimeConstantPool) {
        this.runtimeConstantPool = runtimeConstantPool;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public void setClazz(VMClass clazz) {
        this.clazz = clazz;
    }
}
